{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# todo： 数据清洗 将NaN新生和为负的数据进行清洗"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn.ensemble import RandomForestClassifier\n",
    "from sklearn.ensemble import GradientBoostingClassifier\n",
    "from xgboost import XGBClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "college.to_csv('input/1.csv',index=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "IOError",
     "evalue": "[Errno 2] No such file or directory: 'input/college.csv'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIOError\u001b[0m                                   Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-3-6cd4d3f28c10>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     18\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     19\u001b[0m \u001b[0mcollege\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mDataFrame\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mscore_train_test\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgroupby\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'college'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'rank'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmax\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 20\u001b[1;33m \u001b[0mcollege\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mto_csv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'input/college.csv'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     21\u001b[0m \u001b[0mcollege\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread_csv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'input/college.csv'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     22\u001b[0m \u001b[0mcollege\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m'college'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'total_people'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m/home/kuhung/anaconda2/lib/python2.7/site-packages/pandas/core/frame.pyc\u001b[0m in \u001b[0;36mto_csv\u001b[1;34m(self, path_or_buf, sep, na_rep, float_format, columns, header, index, index_label, mode, encoding, compression, quoting, quotechar, line_terminator, chunksize, tupleize_cols, date_format, doublequote, escapechar, decimal, **kwds)\u001b[0m\n\u001b[0;32m   1342\u001b[0m                                      \u001b[0mdoublequote\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mdoublequote\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1343\u001b[0m                                      escapechar=escapechar, decimal=decimal)\n\u001b[1;32m-> 1344\u001b[1;33m         \u001b[0mformatter\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msave\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1345\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1346\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mpath_or_buf\u001b[0m \u001b[1;32mis\u001b[0m \u001b[0mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m/home/kuhung/anaconda2/lib/python2.7/site-packages/pandas/formats/format.pyc\u001b[0m in \u001b[0;36msave\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m   1524\u001b[0m             f = _get_handle(self.path_or_buf, self.mode,\n\u001b[0;32m   1525\u001b[0m                             \u001b[0mencoding\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mencoding\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1526\u001b[1;33m                             compression=self.compression)\n\u001b[0m\u001b[0;32m   1527\u001b[0m             \u001b[0mclose\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mTrue\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1528\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m/home/kuhung/anaconda2/lib/python2.7/site-packages/pandas/io/common.pyc\u001b[0m in \u001b[0;36m_get_handle\u001b[1;34m(path, mode, encoding, compression)\u001b[0m\n\u001b[0;32m    424\u001b[0m                 \u001b[0mf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0merrors\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'replace'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    425\u001b[0m         \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 426\u001b[1;33m             \u001b[0mf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    427\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    428\u001b[0m     \u001b[1;32mreturn\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mIOError\u001b[0m: [Errno 2] No such file or directory: 'input/college.csv'"
     ]
    }
   ],
   "source": [
    "train = pd.read_table('train/subsidy_train.txt',sep=',',header=-1)\n",
    "train.columns = ['id','label']\n",
    "test = pd.read_table('test/studentID_test.txt',sep=',',header=-1)\n",
    "test.columns = ['id']\n",
    "test['label'] = np.nan\n",
    "\n",
    "#train_test = pd.concat([train,test])\n",
    "train_test=train\n",
    "\n",
    "del train\n",
    "del test\n",
    "\n",
    "score_train = pd.read_table('train/score_train.txt',sep=',',header=-1)\n",
    "score_train.columns = ['id','college','rank']\n",
    "score_test = pd.read_table('test/score_test.txt',sep=',',header=-1)\n",
    "score_test.columns = ['id','college','rank']\n",
    "score_train_test = pd.concat([score_train,score_test])\n",
    "\n",
    "college = pd.DataFrame(score_train_test.groupby(['college'])['rank'].max())\n",
    "college.to_csv('input/college.csv',index=True)\n",
    "college = pd.read_csv('input/college.csv')\n",
    "college.columns = ['college','total_people']\n",
    "\n",
    "score_train_test = pd.merge(score_train_test, college, how='left',on='college')\n",
    "score_train_test['rank_percent'] = score_train_test['rank']/score_train_test['total_people']\n",
    "train_test = pd.merge(train_test,score_train_test,how='left',on='id')\n",
    "\n",
    "card_train = pd.read_table('train/card_train.txt',sep=',',header=-1)\n",
    "card_train.columns = ['id','pos','place','consume','time','price','rest']\n",
    "#card_test = pd.read_table('test/card_test.txt',sep=',',header=-1)\n",
    "#card_test.columns = ['id','pos','place','consume','time','price','rest']\n",
    "#\n",
    "#card_train_test = pd.concat([card_train,card_test])\n",
    "card_train_test=card_train\n",
    "print \"Read OK!\"\n",
    "\n",
    "##release memery\n",
    "del card_train\n",
    "#del card_test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#card_train_test=card_train_test.drop_duplicates()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#card_train_test.drop(['place','time'],axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(12455558, 7)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "card_train_test.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(110472, 7)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "card_train_test[card_train_test['price']<0].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "confuse_data=card_train_test[card_train_test['price']<0]#['consume'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>pos</th>\n",
       "      <th>place</th>\n",
       "      <th>consume</th>\n",
       "      <th>time</th>\n",
       "      <th>price</th>\n",
       "      <th>rest</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2013/09/01 00:02:40</td>\n",
       "      <td>1.20</td>\n",
       "      <td>200.71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2013/09/01 00:02:40</td>\n",
       "      <td>-0.48</td>\n",
       "      <td>201.19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2013/09/01 00:02:40</td>\n",
       "      <td>-0.48</td>\n",
       "      <td>201.19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2013/09/01 00:02:40</td>\n",
       "      <td>1.20</td>\n",
       "      <td>200.71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>122</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2013/09/01 00:20:11</td>\n",
       "      <td>1.20</td>\n",
       "      <td>199.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>123</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2013/09/01 00:20:11</td>\n",
       "      <td>1.20</td>\n",
       "      <td>199.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>152</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2013/09/01 00:29:12</td>\n",
       "      <td>-0.66</td>\n",
       "      <td>200.65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2013/09/01 00:29:12</td>\n",
       "      <td>-0.66</td>\n",
       "      <td>200.65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>154</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2013/09/01 00:29:22</td>\n",
       "      <td>1.20</td>\n",
       "      <td>199.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>155</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2013/09/01 00:29:22</td>\n",
       "      <td>-1.08</td>\n",
       "      <td>200.53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>156</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2013/09/01 00:29:22</td>\n",
       "      <td>1.20</td>\n",
       "      <td>199.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>157</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2013/09/01 00:29:22</td>\n",
       "      <td>-1.08</td>\n",
       "      <td>200.53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>188</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2013/09/01 00:35:44</td>\n",
       "      <td>1.20</td>\n",
       "      <td>199.33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>189</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2013/09/01 00:35:44</td>\n",
       "      <td>-0.96</td>\n",
       "      <td>200.29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>190</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2013/09/01 00:35:44</td>\n",
       "      <td>-0.96</td>\n",
       "      <td>200.29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>191</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2013/09/01 00:35:44</td>\n",
       "      <td>1.20</td>\n",
       "      <td>199.33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7252</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点213</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2013/09/01 09:55:04</td>\n",
       "      <td>0.90</td>\n",
       "      <td>199.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7253</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点213</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2013/09/01 09:55:04</td>\n",
       "      <td>0.90</td>\n",
       "      <td>199.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39130</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点821</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2013/09/02 12:00:25</td>\n",
       "      <td>5.60</td>\n",
       "      <td>193.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40125</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点217</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2013/09/02 12:08:45</td>\n",
       "      <td>4.70</td>\n",
       "      <td>189.09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59091</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点21</td>\n",
       "      <td>开水</td>\n",
       "      <td>2013/09/03 11:55:03</td>\n",
       "      <td>2.60</td>\n",
       "      <td>186.49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64094</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点26</td>\n",
       "      <td>图书馆</td>\n",
       "      <td>2013/09/03 17:13:36</td>\n",
       "      <td>5.00</td>\n",
       "      <td>181.49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64304</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点21</td>\n",
       "      <td>开水</td>\n",
       "      <td>2013/09/03 17:26:45</td>\n",
       "      <td>3.60</td>\n",
       "      <td>177.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80980</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点154</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2013/09/04 12:09:06</td>\n",
       "      <td>4.60</td>\n",
       "      <td>173.29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86955</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点59</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2013/09/04 18:08:13</td>\n",
       "      <td>4.60</td>\n",
       "      <td>168.69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93545</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点240</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2013/09/05 07:20:05</td>\n",
       "      <td>0.50</td>\n",
       "      <td>168.19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101171</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点21</td>\n",
       "      <td>开水</td>\n",
       "      <td>2013/09/05 12:20:39</td>\n",
       "      <td>4.60</td>\n",
       "      <td>163.59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101528</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点217</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2013/09/05 12:28:56</td>\n",
       "      <td>1.80</td>\n",
       "      <td>161.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>108371</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点190</td>\n",
       "      <td>超市</td>\n",
       "      <td>2013/09/05 20:41:54</td>\n",
       "      <td>13.30</td>\n",
       "      <td>148.49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>124732</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点161</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2013/09/06 17:57:39</td>\n",
       "      <td>5.60</td>\n",
       "      <td>142.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4975735</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点226</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2014/07/04 17:10:49</td>\n",
       "      <td>1.50</td>\n",
       "      <td>88.31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4975788</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点21</td>\n",
       "      <td>开水</td>\n",
       "      <td>2014/07/04 17:12:19</td>\n",
       "      <td>5.40</td>\n",
       "      <td>89.81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4991849</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点240</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2014/07/05 17:22:45</td>\n",
       "      <td>5.10</td>\n",
       "      <td>83.21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5008613</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点273</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2014/07/06 17:28:25</td>\n",
       "      <td>8.80</td>\n",
       "      <td>74.41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5008876</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点245</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2014/07/06 17:31:55</td>\n",
       "      <td>1.20</td>\n",
       "      <td>73.21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5019589</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点273</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2014/07/07 11:43:07</td>\n",
       "      <td>10.20</td>\n",
       "      <td>63.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5019777</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点245</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2014/07/07 11:46:41</td>\n",
       "      <td>1.50</td>\n",
       "      <td>61.51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5024324</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点273</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2014/07/07 17:29:08</td>\n",
       "      <td>5.80</td>\n",
       "      <td>55.71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5024510</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点245</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2014/07/07 17:32:36</td>\n",
       "      <td>1.20</td>\n",
       "      <td>54.51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5028217</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点37</td>\n",
       "      <td>淋浴</td>\n",
       "      <td>2014/07/07 21:57:12</td>\n",
       "      <td>0.70</td>\n",
       "      <td>53.81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5028490</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2014/07/07 22:15:56</td>\n",
       "      <td>1.20</td>\n",
       "      <td>52.61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5028491</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2014/07/07 22:15:56</td>\n",
       "      <td>-0.12</td>\n",
       "      <td>52.73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5028770</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2014/07/07 22:40:53</td>\n",
       "      <td>1.20</td>\n",
       "      <td>51.53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5028771</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点661</td>\n",
       "      <td>洗衣房</td>\n",
       "      <td>2014/07/07 22:40:53</td>\n",
       "      <td>-1.08</td>\n",
       "      <td>52.61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5033650</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点226</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2014/07/08 11:26:49</td>\n",
       "      <td>1.00</td>\n",
       "      <td>45.61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5033732</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点21</td>\n",
       "      <td>开水</td>\n",
       "      <td>2014/07/08 11:28:04</td>\n",
       "      <td>6.00</td>\n",
       "      <td>46.61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5039724</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点273</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2014/07/08 17:21:09</td>\n",
       "      <td>6.20</td>\n",
       "      <td>39.41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5039930</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点245</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2014/07/08 17:24:48</td>\n",
       "      <td>1.50</td>\n",
       "      <td>37.91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5040313</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点841</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2014/07/08 17:33:17</td>\n",
       "      <td>2.00</td>\n",
       "      <td>35.91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5048642</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点21</td>\n",
       "      <td>开水</td>\n",
       "      <td>2014/07/09 11:23:06</td>\n",
       "      <td>5.10</td>\n",
       "      <td>30.81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5048737</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点21</td>\n",
       "      <td>开水</td>\n",
       "      <td>2014/07/09 11:25:44</td>\n",
       "      <td>1.00</td>\n",
       "      <td>29.81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5056999</th>\n",
       "      <td>1040</td>\n",
       "      <td>圈存转账</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2014/07/09 19:41:44</td>\n",
       "      <td>100.00</td>\n",
       "      <td>129.81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5057003</th>\n",
       "      <td>1040</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2014/07/09 19:42:40</td>\n",
       "      <td>100.00</td>\n",
       "      <td>29.81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5062303</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点226</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2014/07/10 11:17:09</td>\n",
       "      <td>1.20</td>\n",
       "      <td>22.61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5062430</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点21</td>\n",
       "      <td>开水</td>\n",
       "      <td>2014/07/10 11:20:09</td>\n",
       "      <td>6.00</td>\n",
       "      <td>23.81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5066299</th>\n",
       "      <td>1040</td>\n",
       "      <td>圈存转账</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2014/07/10 17:10:43</td>\n",
       "      <td>200.00</td>\n",
       "      <td>222.61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5066303</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点273</td>\n",
       "      <td>食堂</td>\n",
       "      <td>2014/07/10 17:10:50</td>\n",
       "      <td>7.50</td>\n",
       "      <td>215.11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5281411</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点53</td>\n",
       "      <td>淋浴</td>\n",
       "      <td>2014/08/31 22:12:27</td>\n",
       "      <td>0.10</td>\n",
       "      <td>215.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5281415</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点53</td>\n",
       "      <td>淋浴</td>\n",
       "      <td>2014/08/31 22:12:35</td>\n",
       "      <td>0.10</td>\n",
       "      <td>214.91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5281469</th>\n",
       "      <td>1040</td>\n",
       "      <td>POS消费</td>\n",
       "      <td>地点6</td>\n",
       "      <td>淋浴</td>\n",
       "      <td>2014/08/31 22:14:34</td>\n",
       "      <td>0.70</td>\n",
       "      <td>214.21</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1082 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           id    pos  place consume                 time   price    rest\n",
       "18       1040  POS消费  地点661     洗衣房  2013/09/01 00:02:40    1.20  200.71\n",
       "19       1040  POS消费  地点661     洗衣房  2013/09/01 00:02:40   -0.48  201.19\n",
       "20       1040  POS消费  地点661     洗衣房  2013/09/01 00:02:40   -0.48  201.19\n",
       "21       1040  POS消费  地点661     洗衣房  2013/09/01 00:02:40    1.20  200.71\n",
       "122      1040  POS消费  地点661     洗衣房  2013/09/01 00:20:11    1.20  199.99\n",
       "123      1040  POS消费  地点661     洗衣房  2013/09/01 00:20:11    1.20  199.99\n",
       "152      1040  POS消费  地点661     洗衣房  2013/09/01 00:29:12   -0.66  200.65\n",
       "153      1040  POS消费  地点661     洗衣房  2013/09/01 00:29:12   -0.66  200.65\n",
       "154      1040  POS消费  地点661     洗衣房  2013/09/01 00:29:22    1.20  199.45\n",
       "155      1040  POS消费  地点661     洗衣房  2013/09/01 00:29:22   -1.08  200.53\n",
       "156      1040  POS消费  地点661     洗衣房  2013/09/01 00:29:22    1.20  199.45\n",
       "157      1040  POS消费  地点661     洗衣房  2013/09/01 00:29:22   -1.08  200.53\n",
       "188      1040  POS消费  地点661     洗衣房  2013/09/01 00:35:44    1.20  199.33\n",
       "189      1040  POS消费  地点661     洗衣房  2013/09/01 00:35:44   -0.96  200.29\n",
       "190      1040  POS消费  地点661     洗衣房  2013/09/01 00:35:44   -0.96  200.29\n",
       "191      1040  POS消费  地点661     洗衣房  2013/09/01 00:35:44    1.20  199.33\n",
       "7252     1040  POS消费  地点213      食堂  2013/09/01 09:55:04    0.90  199.39\n",
       "7253     1040  POS消费  地点213      食堂  2013/09/01 09:55:04    0.90  199.39\n",
       "39130    1040  POS消费  地点821      食堂  2013/09/02 12:00:25    5.60  193.79\n",
       "40125    1040  POS消费  地点217      食堂  2013/09/02 12:08:45    4.70  189.09\n",
       "59091    1040  POS消费   地点21      开水  2013/09/03 11:55:03    2.60  186.49\n",
       "64094    1040  POS消费   地点26     图书馆  2013/09/03 17:13:36    5.00  181.49\n",
       "64304    1040  POS消费   地点21      开水  2013/09/03 17:26:45    3.60  177.89\n",
       "80980    1040  POS消费  地点154      食堂  2013/09/04 12:09:06    4.60  173.29\n",
       "86955    1040  POS消费   地点59      食堂  2013/09/04 18:08:13    4.60  168.69\n",
       "93545    1040  POS消费  地点240      食堂  2013/09/05 07:20:05    0.50  168.19\n",
       "101171   1040  POS消费   地点21      开水  2013/09/05 12:20:39    4.60  163.59\n",
       "101528   1040  POS消费  地点217      食堂  2013/09/05 12:28:56    1.80  161.79\n",
       "108371   1040  POS消费  地点190      超市  2013/09/05 20:41:54   13.30  148.49\n",
       "124732   1040  POS消费  地点161      食堂  2013/09/06 17:57:39    5.60  142.89\n",
       "...       ...    ...    ...     ...                  ...     ...     ...\n",
       "4975735  1040  POS消费  地点226      食堂  2014/07/04 17:10:49    1.50   88.31\n",
       "4975788  1040  POS消费   地点21      开水  2014/07/04 17:12:19    5.40   89.81\n",
       "4991849  1040  POS消费  地点240      食堂  2014/07/05 17:22:45    5.10   83.21\n",
       "5008613  1040  POS消费  地点273      食堂  2014/07/06 17:28:25    8.80   74.41\n",
       "5008876  1040  POS消费  地点245      食堂  2014/07/06 17:31:55    1.20   73.21\n",
       "5019589  1040  POS消费  地点273      食堂  2014/07/07 11:43:07   10.20   63.01\n",
       "5019777  1040  POS消费  地点245      食堂  2014/07/07 11:46:41    1.50   61.51\n",
       "5024324  1040  POS消费  地点273      食堂  2014/07/07 17:29:08    5.80   55.71\n",
       "5024510  1040  POS消费  地点245      食堂  2014/07/07 17:32:36    1.20   54.51\n",
       "5028217  1040  POS消费   地点37      淋浴  2014/07/07 21:57:12    0.70   53.81\n",
       "5028490  1040  POS消费  地点661     洗衣房  2014/07/07 22:15:56    1.20   52.61\n",
       "5028491  1040  POS消费  地点661     洗衣房  2014/07/07 22:15:56   -0.12   52.73\n",
       "5028770  1040  POS消费  地点661     洗衣房  2014/07/07 22:40:53    1.20   51.53\n",
       "5028771  1040  POS消费  地点661     洗衣房  2014/07/07 22:40:53   -1.08   52.61\n",
       "5033650  1040  POS消费  地点226      食堂  2014/07/08 11:26:49    1.00   45.61\n",
       "5033732  1040  POS消费   地点21      开水  2014/07/08 11:28:04    6.00   46.61\n",
       "5039724  1040  POS消费  地点273      食堂  2014/07/08 17:21:09    6.20   39.41\n",
       "5039930  1040  POS消费  地点245      食堂  2014/07/08 17:24:48    1.50   37.91\n",
       "5040313  1040  POS消费  地点841      食堂  2014/07/08 17:33:17    2.00   35.91\n",
       "5048642  1040  POS消费   地点21      开水  2014/07/09 11:23:06    5.10   30.81\n",
       "5048737  1040  POS消费   地点21      开水  2014/07/09 11:25:44    1.00   29.81\n",
       "5056999  1040   圈存转账    NaN     NaN  2014/07/09 19:41:44  100.00  129.81\n",
       "5057003  1040    NaN    NaN     NaN  2014/07/09 19:42:40  100.00   29.81\n",
       "5062303  1040  POS消费  地点226      食堂  2014/07/10 11:17:09    1.20   22.61\n",
       "5062430  1040  POS消费   地点21      开水  2014/07/10 11:20:09    6.00   23.81\n",
       "5066299  1040   圈存转账    NaN     NaN  2014/07/10 17:10:43  200.00  222.61\n",
       "5066303  1040  POS消费  地点273      食堂  2014/07/10 17:10:50    7.50  215.11\n",
       "5281411  1040  POS消费   地点53      淋浴  2014/08/31 22:12:27    0.10  215.01\n",
       "5281415  1040  POS消费   地点53      淋浴  2014/08/31 22:12:35    0.10  214.91\n",
       "5281469  1040  POS消费    地点6      淋浴  2014/08/31 22:14:34    0.70  214.21\n",
       "\n",
       "[1082 rows x 7 columns]"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "card_train_test[card_train_test['id']==1040]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8460"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "card_train_test[card_train_test['price']<0]['id'].drop_duplicates().count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       9325\n",
       "1000     741\n",
       "1500     465\n",
       "2000     354\n",
       "Name: label, dtype: int64"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_test.label.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "drop=set(card_train_test[card_train_test['price']<0]['id'].drop_duplicates())&set(train_test[train_test['label']!=0]['id'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1395\n"
     ]
    }
   ],
   "source": [
    "c=0\n",
    "for item in drop:\n",
    "    c=c+1\n",
    "    \n",
    "print c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "negative=pd.DataFrame(confuse_data.groupby(['id'])['id'].count())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "negative.to_csv('input/negative_count.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "negative=pd.read_csv('input/negative_count.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "negative.columns=['id','count']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train = pd.read_table('train/subsidy_train.txt',sep=',',header=-1)\n",
    "train.columns = ['id','label']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "ob=negative.merge(train,on='id',how='outer')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7f6753d1d150>"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    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WxRdKmi1U\nkq4Afhf4pYj4iaRVVP8exZ9ExJ9K+m3gs8A/rlO9eJngaqp/EOkU8JCkfxARn5X0cWAoImr//ozZ\nguQzFbPZ+RXgG+Nv+un5l4D/lY5/ler3gV3MSEQ8HdXr0Yep/pU9mPzFm2YLmpOKWX6NFipfI/2f\nS9+QXSoc+/vC9uv4KoItUk4qZrPzAPDPJPUBpOf/C/yLdPz9wF+l7QrwC2n7RqCrifZ/CvTkGqzZ\nXPNvQ2azEBGjkv4b8JeSXqP6leIfA74k6d8DZ6h+tT/AF4C70p/ivQ94sVGzhe0vAPdKeioifnVO\nJmGWkW8pNjOzbHz5y8zMsnFSMTOzbJxUzMwsGycVMzPLxknFzMyycVIxM7NsnFTMzCwbJxUzM8vm\n/wMLPnzSHUflyQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f6753b9c0d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ob.plot.scatter(x='count',y='label')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7          22.0\n",
       "8          23.0\n",
       "9          28.0\n",
       "13         64.0\n",
       "22         92.0\n",
       "23         93.0\n",
       "24         99.0\n",
       "28        138.0\n",
       "38        160.0\n",
       "39        161.0\n",
       "47        186.0\n",
       "58        220.0\n",
       "63        232.0\n",
       "66        238.0\n",
       "68        244.0\n",
       "69        245.0\n",
       "82        296.0\n",
       "83        297.0\n",
       "101       398.0\n",
       "102       399.0\n",
       "104       408.0\n",
       "105       409.0\n",
       "106       412.0\n",
       "107       413.0\n",
       "110       430.0\n",
       "111       431.0\n",
       "122       476.0\n",
       "123       477.0\n",
       "124       480.0\n",
       "132       510.0\n",
       "         ...   \n",
       "9051    18461.0\n",
       "9052    18471.0\n",
       "9059    18621.0\n",
       "9060    18657.0\n",
       "9061    18681.0\n",
       "9074    18795.0\n",
       "9078    18867.0\n",
       "9080    18989.0\n",
       "9082    19043.0\n",
       "9088    19123.0\n",
       "9093    19203.0\n",
       "9097    19259.0\n",
       "9099    19347.0\n",
       "9107    19695.0\n",
       "9110    19771.0\n",
       "9113    19841.0\n",
       "9122    20009.0\n",
       "9126    20073.0\n",
       "9129    20201.0\n",
       "9134    20301.0\n",
       "9141    20387.0\n",
       "9142    20395.0\n",
       "9147    20417.0\n",
       "9154    20515.0\n",
       "9158    20627.0\n",
       "9162    20767.0\n",
       "9197    21247.0\n",
       "9198    21249.0\n",
       "9201    21323.0\n",
       "9211    21453.0\n",
       "Name: id, dtype: float64"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ob[ob['label']!=0].id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "##这里的consume是有问题的，consume一列包含刷卡和消费\n",
    "\n",
    "## bash feature\n",
    "card = pd.DataFrame(card_train_test.groupby(['id'])['pos'].count())\n",
    "\n",
    "card['price_sum'] = card_train_test.groupby(['id'])['price'].sum()\n",
    "card['price_avg'] = card_train_test.groupby(['id'])['price'].mean()\n",
    "#\n",
    "card['price_max'] = card_train_test.groupby(['id'])['price'].max()\n",
    "card['price_min'] = card_train_test.groupby(['id'])['price'].min()\n",
    "card['price_median'] = card_train_test.groupby(['id'])['price'].median()\n",
    "\n",
    "card['rest_sum'] = card_train_test.groupby(['id'])['rest'].sum()\n",
    "card['rest_avg'] = card_train_test.groupby(['id'])['rest'].mean()\n",
    "card['rest_max'] = card_train_test.groupby(['id'])['rest'].max()\n",
    "card['rest_min'] = card_train_test.groupby(['id'])['rest'].min()\n",
    "card['rest_median'] = card_train_test.groupby(['id'])['rest'].median()\n",
    "\n",
    "card.to_csv('input/card_bashfeature.csv',index=True)\n",
    "card = pd.read_csv('input/card_bashfeature.csv') \n",
    "card=card.rename(columns={'pos' : 'price_count'}) \n",
    "\n",
    "train_test = pd.merge(train_test, card, how='left',on='id') #2512\n",
    "del card"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"\\n## recharge feature\\nrecharge=card_train_test[(card_train_test.pos=='\\xe5\\x8d\\xa1\\xe5\\x85\\x85\\xe5\\x80\\xbc') | (card_train_test.pos=='\\xe5\\x9c\\x88\\xe5\\xad\\x98\\xe8\\xbd\\xac\\xe8\\xb4\\xa6') ]\\n\\ncard_recharge = pd.DataFrame(recharge.groupby(['id'])['pos'].count())\\n\\ncard_recharge['recharge_sum']=recharge.groupby(['id'])['price'].sum()\\ncard_recharge['recharge_avg']=recharge.groupby(['id'])['price'].mean()\\n#\\ncard_recharge['recharge_max']=recharge.groupby(['id'])['price'].max()\\ncard_recharge['recharge_min']=recharge.groupby(['id'])['price'].min()\\n#\\ncard_recharge['recharge_median']=recharge.groupby(['id'])['price'].median() #2330\\n\\n\\ndel recharge\\ncard_recharge.to_csv('input/card_rechargefeature.csv',index=True)\\ncard_recharge = pd.read_csv('input/card_rechargefeature.csv') \\ncard_recharge=card_recharge.rename(columns={'pos' : 'recharge_count'}) \\n\\ntrain_test = pd.merge(train_test, card_recharge, how='left',on='id') \\ndel card_recharge\\n\\n## \\xe6\\x94\\xaf\\xe4\\xbb\\x98\\xe9\\xa2\\x86\\xe5\\x8f\\x96\\xe9\\xa1\\xb9\\nzhifu = card_train_test[card_train_test.pos=='\\xe6\\x94\\xaf\\xe4\\xbb\\x98\\xe9\\xa2\\x86\\xe5\\x8f\\x96']\\ncard_zhifu= pd.DataFrame(zhifu.groupby(['id'])['pos'].count())\\n\\ncard_zhifu['zhifu_sum'] = zhifu.groupby(['id'])['price'].sum()\\ncard_zhifu['zhifu_avg'] = zhifu.groupby(['id'])['price'].mean()\\n#\\ncard_zhifu['zhifu_max'] = zhifu.groupby(['id'])['price'].max()\\ncard_zhifu['zhifu_min'] = zhifu.groupby(['id'])['price'].min()\\n#\\ncard_zhifu['zhifu_median'] = zhifu.groupby(['id'])['price'].median()\\n\\ndel zhifu\\ncard_zhifu.to_csv('input/card_zhifufeature.csv',index=True)\\ncard_zhifu = pd.read_csv('input/card_zhifufeature.csv') \\ncard_zhifu=card_zhifu.rename(columns={'pos' : 'zhifu_count'}) \\n\\n\\ntrain_test = pd.merge(train_test, card_zhifu, how='left',on='id')\\ndel card_zhifu\\n\\n\""
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "## recharge feature\n",
    "recharge=card_train_test[(card_train_test.pos=='卡充值') | (card_train_test.pos=='圈存转账') ]\n",
    "\n",
    "card_recharge = pd.DataFrame(recharge.groupby(['id'])['pos'].count())\n",
    "\n",
    "card_recharge['recharge_sum']=recharge.groupby(['id'])['price'].sum()\n",
    "card_recharge['recharge_avg']=recharge.groupby(['id'])['price'].mean()\n",
    "#\n",
    "card_recharge['recharge_max']=recharge.groupby(['id'])['price'].max()\n",
    "card_recharge['recharge_min']=recharge.groupby(['id'])['price'].min()\n",
    "#\n",
    "card_recharge['recharge_median']=recharge.groupby(['id'])['price'].median() #2330\n",
    "\n",
    "\n",
    "del recharge\n",
    "card_recharge.to_csv('input/card_rechargefeature.csv',index=True)\n",
    "card_recharge = pd.read_csv('input/card_rechargefeature.csv') \n",
    "card_recharge=card_recharge.rename(columns={'pos' : 'recharge_count'}) \n",
    "\n",
    "train_test = pd.merge(train_test, card_recharge, how='left',on='id') \n",
    "del card_recharge\n",
    "\n",
    "## 支付领取项\n",
    "zhifu = card_train_test[card_train_test.pos=='支付领取']\n",
    "card_zhifu= pd.DataFrame(zhifu.groupby(['id'])['pos'].count())\n",
    "\n",
    "card_zhifu['zhifu_sum'] = zhifu.groupby(['id'])['price'].sum()\n",
    "card_zhifu['zhifu_avg'] = zhifu.groupby(['id'])['price'].mean()\n",
    "#\n",
    "card_zhifu['zhifu_max'] = zhifu.groupby(['id'])['price'].max()\n",
    "card_zhifu['zhifu_min'] = zhifu.groupby(['id'])['price'].min()\n",
    "#\n",
    "card_zhifu['zhifu_median'] = zhifu.groupby(['id'])['price'].median()\n",
    "\n",
    "del zhifu\n",
    "card_zhifu.to_csv('input/card_zhifufeature.csv',index=True)\n",
    "card_zhifu = pd.read_csv('input/card_zhifufeature.csv') \n",
    "card_zhifu=card_zhifu.rename(columns={'pos' : 'zhifu_count'}) \n",
    "\n",
    "\n",
    "train_test = pd.merge(train_test, card_zhifu, how='left',on='id')\n",
    "del card_zhifu\n",
    "\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "## consume feature\n",
    "consume=card_train_test[card_train_test.pos == 'POS消费']\n",
    "\n",
    "card_consume = pd.DataFrame(consume.groupby(['id'])['pos'].count())\n",
    "\n",
    "card_consume['consume_sum']=consume.groupby(['id'])['price'].sum()\n",
    "card_consume['consume_avg']=consume.groupby(['id'])['price'].mean()\n",
    "card_consume['consume_max']=consume.groupby(['id'])['price'].max()\n",
    "card_consume['consume_min']=consume.groupby(['id'])['price'].min()\n",
    "card_consume['consume_median']=consume.groupby(['id'])['price'].median()\n",
    "\n",
    "del consume\n",
    "card_consume.to_csv('input/card_consumefeature.csv',index=True)\n",
    "card_consume = pd.read_csv('input/card_consumefeature.csv') \n",
    "card_consume=card_consume.rename(columns={'pos' : 'consume_count'}) \n",
    "\n",
    "\n",
    "train_test = pd.merge(train_test, card_consume, how='left',on='id') \n",
    "del card_consume"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "kapiankaihu=card_train_test[card_train_test.pos=='卡片开户']\n",
    "card_kaihu = pd.DataFrame(kapiankaihu.groupby(['id'])['pos'].count())\n",
    "del kapiankaihu\n",
    "card_kaihu.to_csv('input/card_kaihufeature.csv',index=True)\n",
    "card_kaihu = pd.read_csv('input/card_kaihufeature.csv') \n",
    "card_kaihu=card_kaihu.rename(columns={'pos' : 'kaihu_count'}) \n",
    "\n",
    "train_test = pd.merge(train_test, card_kaihu, how='left',on='id') \n",
    "del card_kaihu\n",
    "\n",
    "kapianxiaohu=card_train_test[card_train_test.pos=='卡片销户']\n",
    "card_xiaohu = pd.DataFrame(kapianxiaohu.groupby(['id'])['pos'].count())\n",
    "del kapianxiaohu\n",
    "card_xiaohu.to_csv('input/card_xiaohufeature.csv',index=True)\n",
    "card_xiaohu = pd.read_csv('input/card_xiaohufeature.csv') \n",
    "card_xiaohu=card_xiaohu.rename(columns={'pos' : 'xiaohu_count'}) \n",
    "\n",
    "train_test = pd.merge(train_test, card_xiaohu, how='left',on='id') \n",
    "del card_xiaohu\n",
    "\n",
    "kapianbuban=card_train_test[card_train_test.pos=='卡补办']\n",
    "card_buban = pd.DataFrame(kapianbuban.groupby(['id'])['pos'].count())\n",
    "del kapianbuban\n",
    "card_buban.to_csv('input/card_bubanfeature.csv',index=True)\n",
    "card_buban = pd.read_csv('input/card_bubanfeature.csv') \n",
    "card_buban=card_buban.rename(columns={'pos' : 'buban_count'}) \n",
    "\n",
    "train_test = pd.merge(train_test, card_buban, how='left',on='id') \n",
    "del card_buban\n",
    "\n",
    "kapianjiegua=card_train_test[card_train_test.pos=='卡解挂']\n",
    "card_jiegua = pd.DataFrame(kapianjiegua.groupby(['id'])['pos'].count())\n",
    "del kapianjiegua\n",
    "card_jiegua.to_csv('input/card_jieguafeature.csv',index=True)\n",
    "card_jiegua = pd.read_csv('input/card_jieguafeature.csv') \n",
    "card_jiegua=card_jiegua.rename(columns={'pos' : 'jiegua_count'}) \n",
    "\n",
    "train_test = pd.merge(train_test, card_jiegua, how='left',on='id') \n",
    "del card_jiegua\n",
    "\n",
    "kapianchange=card_train_test[card_train_test.pos=='换卡']\n",
    "card_change = pd.DataFrame(kapianchange.groupby(['id'])['pos'].count())\n",
    "del kapianchange\n",
    "card_change.to_csv('input/card_changefeature.csv',index=True)\n",
    "card_change = pd.read_csv('input/card_changefeature.csv') \n",
    "card_change=card_change.rename(columns={'pos' : 'change_count'}) \n",
    "\n",
    "train_test = pd.merge(train_test, card_change, how='left',on='id') \n",
    "del card_change\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "\n",
    "canteen=card_train_test[card_train_test.consume=='食堂']\n",
    "\n",
    "card_canteen = pd.DataFrame(canteen.groupby(['id'])['pos'].count())\n",
    "card_canteen['canteen_sum']=canteen.groupby(['id'])['price'].sum()\n",
    "card_canteen['canteen_avg']=canteen.groupby(['id'])['price'].mean()\n",
    "card_canteen['canteen_max']=canteen.groupby(['id'])['price'].max()\n",
    "card_canteen['canteen_min']=canteen.groupby(['id'])['price'].min()\n",
    "card_canteen['canteen_median']=canteen.groupby(['id'])['price'].median()\n",
    "\n",
    "del canteen\n",
    "card_canteen.to_csv('input/card_canteenfeature.csv',index=True)\n",
    "card_canteen = pd.read_csv('input/card_canteenfeature.csv') \n",
    "card_canteen=card_canteen.rename(columns={'pos' : 'canteen_count'}) \n",
    "\n",
    "train_test = pd.merge(train_test, card_canteen, how='left',on='id') \n",
    "del card_canteen\n",
    "\n",
    "boiled_water=card_train_test[card_train_test.consume=='开水']\n",
    "\n",
    "card_boiled_water = pd.DataFrame(boiled_water.groupby(['id'])['pos'].count())\n",
    "card_boiled_water['boiled_water_sum']=boiled_water.groupby(['id'])['price'].sum()\n",
    "card_boiled_water['boiled_water_avg']=boiled_water.groupby(['id'])['price'].mean()\n",
    "card_boiled_water['boiled_water_max']=boiled_water.groupby(['id'])['price'].max()\n",
    "card_boiled_water['boiled_water_min']=boiled_water.groupby(['id'])['price'].min()\n",
    "card_boiled_water['boiled_water_median']=boiled_water.groupby(['id'])['price'].median()\n",
    "\n",
    "del boiled_water\n",
    "card_boiled_water.to_csv('input/card_boiled_waterfeature.csv',index=True)\n",
    "card_boiled_water = pd.read_csv('input/card_boiled_waterfeature.csv') \n",
    "card_boiled_water=card_boiled_water.rename(columns={'pos' : 'boiled_water_count'}) \n",
    "\n",
    "train_test = pd.merge(train_test, card_boiled_water, how='left',on='id') \n",
    "del card_boiled_water\n",
    "\n",
    "bathe=card_train_test[card_train_test.consume=='淋浴']\n",
    "\n",
    "card_bathe = pd.DataFrame(bathe.groupby(['id'])['pos'].count())\n",
    "card_bathe['bathe_sum']=bathe.groupby(['id'])['price'].sum()\n",
    "card_bathe['bathe_avg']=bathe.groupby(['id'])['price'].mean()\n",
    "card_bathe['bathe_max']=bathe.groupby(['id'])['price'].max()\n",
    "card_bathe['bathe_min']=bathe.groupby(['id'])['price'].min()\n",
    "card_bathe['bathe_median']=bathe.groupby(['id'])['price'].median()\n",
    "\n",
    "del bathe\n",
    "card_bathe.to_csv('input/card_bathefeature.csv',index=True)\n",
    "card_bathe = pd.read_csv('input/card_bathefeature.csv') \n",
    "card_bathe=card_bathe.rename(columns={'pos' : 'bathe_count'}) \n",
    "\n",
    "train_test = pd.merge(train_test, card_bathe, how='left',on='id') \n",
    "del card_bathe\n",
    "\n",
    "shool_bus=card_train_test[card_train_test.consume=='校车']\n",
    "\n",
    "card_shool_bus = pd.DataFrame(shool_bus.groupby(['id'])['pos'].count())\n",
    "card_shool_bus['shool_bus_sum']=shool_bus.groupby(['id'])['price'].sum()\n",
    "card_shool_bus['shool_bus_avg']=shool_bus.groupby(['id'])['price'].mean()\n",
    "card_shool_bus['shool_bus_max']=shool_bus.groupby(['id'])['price'].max()\n",
    "card_shool_bus['shool_bus_min']=shool_bus.groupby(['id'])['price'].min()\n",
    "card_shool_bus['shool_bus_median']=shool_bus.groupby(['id'])['price'].median()\n",
    "\n",
    "del shool_bus\n",
    "card_shool_bus.to_csv('input/card_shool_busfeature.csv',index=True)\n",
    "card_shool_bus = pd.read_csv('input/card_shool_busfeature.csv') \n",
    "card_shool_bus=card_shool_bus.rename(columns={'pos' : 'shool_bus_count'}) \n",
    "\n",
    "train_test = pd.merge(train_test, card_shool_bus, how='left',on='id') \n",
    "del card_shool_bus\n",
    "\n",
    "shop=card_train_test[card_train_test.consume=='超市']\n",
    "\n",
    "card_shop = pd.DataFrame(shop.groupby(['id'])['pos'].count())\n",
    "card_shop['shop_sum']=shop.groupby(['id'])['price'].sum()\n",
    "card_shop['shop_avg']=shop.groupby(['id'])['price'].mean()\n",
    "card_shop['shop_max']=shop.groupby(['id'])['price'].max()\n",
    "card_shop['shop_min']=shop.groupby(['id'])['price'].min()\n",
    "card_shop['shop_median']=shop.groupby(['id'])['price'].median()\n",
    "\n",
    "del shop\n",
    "card_shop.to_csv('input/card_shopfeature.csv',index=True)\n",
    "card_shop = pd.read_csv('input/card_shopfeature.csv') \n",
    "card_shop=card_shop.rename(columns={'pos' : 'shop_count'}) \n",
    "\n",
    "train_test = pd.merge(train_test, card_shop, how='left',on='id') \n",
    "del card_shop\n",
    "\n",
    "wash_house=card_train_test[card_train_test.consume=='洗衣房']\n",
    "\n",
    "card_wash_house = pd.DataFrame(wash_house.groupby(['id'])['pos'].count())\n",
    "card_wash_house['wash_sum']=wash_house.groupby(['id'])['price'].sum()\n",
    "card_wash_house['wash_avg']=wash_house.groupby(['id'])['price'].mean()\n",
    "card_wash_house['wash_max']=wash_house.groupby(['id'])['price'].max()\n",
    "card_wash_house['wash_min']=wash_house.groupby(['id'])['price'].min()\n",
    "card_wash_house['wash_median']=wash_house.groupby(['id'])['price'].median()\n",
    "\n",
    "del wash_house\n",
    "card_wash_house.to_csv('input/card_wash_housefeature.csv',index=True)\n",
    "card_wash_house = pd.read_csv('input/card_wash_housefeature.csv') \n",
    "card_wash_house=card_wash_house.rename(columns={'pos' : 'wash_house_count'}) \n",
    "\n",
    "train_test = pd.merge(train_test, card_wash_house, how='left',on='id') \n",
    "del card_wash_house\n",
    "\n",
    "library=card_train_test[card_train_test.consume=='图书馆']\n",
    "\n",
    "card_library= pd.DataFrame(library.groupby(['id'])['pos'].count())\n",
    "card_library['library_sum']=library.groupby(['id'])['price'].sum()\n",
    "card_library['library_avg']=library.groupby(['id'])['price'].mean()\n",
    "card_library['library_max']=library.groupby(['id'])['price'].max()\n",
    "card_library['library_min']=library.groupby(['id'])['price'].min()\n",
    "card_library['library_median']=library.groupby(['id'])['price'].median()\n",
    "\n",
    "del library\n",
    "card_library.to_csv('input/card_libraryfeature.csv',index=True)\n",
    "card_library = pd.read_csv('input/card_libraryfeature.csv') \n",
    "card_library=card_library.rename(columns={'pos' : 'library_count'}) \n",
    "\n",
    "train_test = pd.merge(train_test, card_library, how='left',on='id') \n",
    "del card_library\n",
    "\n",
    "printhouse=card_train_test[card_train_test.consume=='文印中心']\n",
    "\n",
    "card_printhouse= pd.DataFrame(printhouse.groupby(['id'])['pos'].count())\n",
    "card_printhouse['print_sum']=printhouse.groupby(['id'])['price'].sum()\n",
    "card_printhouse['print_avg']=printhouse.groupby(['id'])['price'].mean()\n",
    "card_printhouse['print_max']=printhouse.groupby(['id'])['price'].max()\n",
    "card_printhouse['print_min']=printhouse.groupby(['id'])['price'].min()\n",
    "card_printhouse['print_median']=printhouse.groupby(['id'])['price'].median()\n",
    "\n",
    "del printhouse\n",
    "card_printhouse.to_csv('input/card_printhousefeature.csv',index=True)\n",
    "card_printhouse = pd.read_csv('input/card_printhousefeature.csv') \n",
    "card_printhouse=card_printhouse.rename(columns={'pos' : 'printhouse_count'}) \n",
    "\n",
    "train_test = pd.merge(train_test, card_printhouse, how='left',on='id') \n",
    "del card_printhouse\n",
    "\n",
    "dean=card_train_test[card_train_test.consume=='教务处']\n",
    "\n",
    "card_dean= pd.DataFrame(dean.groupby(['id'])['pos'].count())\n",
    "card_dean['dean_sum']=dean.groupby(['id'])['price'].sum()\n",
    "card_dean['dean_avg']=dean.groupby(['id'])['price'].mean()\n",
    "card_dean['dean_max']=dean.groupby(['id'])['price'].max()\n",
    "card_dean['dean_min']=dean.groupby(['id'])['price'].min()\n",
    "card_dean['dean_median']=dean.groupby(['id'])['price'].median()\n",
    "\n",
    "del dean\n",
    "card_dean.to_csv('input/card_deanfeature.csv',index=True)\n",
    "card_dean = pd.read_csv('input/card_deanfeature.csv') \n",
    "card_dean=card_dean.rename(columns={'pos' : 'dean_count'}) \n",
    "\n",
    "train_test = pd.merge(train_test, card_dean, how='left',on='id') \n",
    "del card_dean\n",
    "\n",
    "other=card_train_test[card_train_test.consume=='其他']\n",
    "\n",
    "card_other= pd.DataFrame(other.groupby(['id'])['pos'].count())\n",
    "card_other['other_sum']=other.groupby(['id'])['price'].sum()\n",
    "#\n",
    "card_other['other_avg']=other.groupby(['id'])['price'].mean()\n",
    "#\n",
    "card_other['other_max']=other.groupby(['id'])['price'].max()\n",
    "#\n",
    "card_other['other_min']=other.groupby(['id'])['price'].min()\n",
    "#\n",
    "card_other['other_median']=other.groupby(['id'])['price'].median()\n",
    "\n",
    "del other\n",
    "card_other.to_csv('input/card_otherfeature.csv',index=True)\n",
    "card_other = pd.read_csv('input/card_otherfeature.csv') \n",
    "card_other=card_other.rename(columns={'pos' : 'other_count'}) \n",
    "\n",
    "train_test = pd.merge(train_test, card_other, how='left',on='id') \n",
    "del card_other\n",
    "\n",
    "hospital=card_train_test[card_train_test.consume=='校医院']\n",
    "\n",
    "card_hospital= pd.DataFrame(hospital.groupby(['id'])['pos'].count())\n",
    "card_hospital['hospital_sum']=hospital.groupby(['id'])['price'].sum()\n",
    "card_hospital['hospital_avg']=hospital.groupby(['id'])['price'].mean()\n",
    "#\n",
    "card_hospital['hospital_max']=hospital.groupby(['id'])['price'].max()\n",
    "card_hospital['hospital_min']=hospital.groupby(['id'])['price'].min()\n",
    "#\n",
    "card_hospital['hospital_median']=hospital.groupby(['id'])['price'].median()\n",
    "\n",
    "del hospital\n",
    "card_hospital.to_csv('input/card_hospitalfeature.csv',index=True)\n",
    "card_hospital = pd.read_csv('input/card_hospitalfeature.csv') \n",
    "card_hospital=card_hospital.rename(columns={'pos' : 'hospital_count'}) \n",
    "\n",
    "train_test = pd.merge(train_test, card_hospital, how='left',on='id') \n",
    "del card_hospital\n",
    "\n",
    "del card_train_test\n",
    "train_test=train_test.fillna(-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>label</th>\n",
       "      <th>college</th>\n",
       "      <th>rank</th>\n",
       "      <th>total_people</th>\n",
       "      <th>rank_percent</th>\n",
       "      <th>price_count</th>\n",
       "      <th>price_sum</th>\n",
       "      <th>price_avg</th>\n",
       "      <th>price_max</th>\n",
       "      <th>...</th>\n",
       "      <th>other_avg</th>\n",
       "      <th>other_max</th>\n",
       "      <th>other_min</th>\n",
       "      <th>other_median</th>\n",
       "      <th>hospital_count</th>\n",
       "      <th>hospital_sum</th>\n",
       "      <th>hospital_avg</th>\n",
       "      <th>hospital_max</th>\n",
       "      <th>hospital_min</th>\n",
       "      <th>hospital_median</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2933.0</td>\n",
       "      <td>0.000341</td>\n",
       "      <td>602.0</td>\n",
       "      <td>4784.14</td>\n",
       "      <td>7.830016</td>\n",
       "      <td>200.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-1.00</td>\n",
       "      <td>-1.00</td>\n",
       "      <td>-1.00</td>\n",
       "      <td>-1.00</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>9.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2933.0</td>\n",
       "      <td>0.000682</td>\n",
       "      <td>666.0</td>\n",
       "      <td>5876.97</td>\n",
       "      <td>8.784709</td>\n",
       "      <td>300.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-1.00</td>\n",
       "      <td>-1.00</td>\n",
       "      <td>-1.00</td>\n",
       "      <td>-1.00</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>1565.0</td>\n",
       "      <td>1570.0</td>\n",
       "      <td>0.996815</td>\n",
       "      <td>1285.0</td>\n",
       "      <td>10779.15</td>\n",
       "      <td>8.388444</td>\n",
       "      <td>200.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-1.00</td>\n",
       "      <td>-1.00</td>\n",
       "      <td>-1.00</td>\n",
       "      <td>-1.00</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>1570.0</td>\n",
       "      <td>1570.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1569.0</td>\n",
       "      <td>14174.15</td>\n",
       "      <td>9.033875</td>\n",
       "      <td>200.0</td>\n",
       "      <td>...</td>\n",
       "      <td>61.13</td>\n",
       "      <td>61.13</td>\n",
       "      <td>61.13</td>\n",
       "      <td>61.13</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2304.0</td>\n",
       "      <td>0.000434</td>\n",
       "      <td>827.0</td>\n",
       "      <td>5976.01</td>\n",
       "      <td>7.191348</td>\n",
       "      <td>200.0</td>\n",
       "      <td>...</td>\n",
       "      <td>-1.00</td>\n",
       "      <td>-1.00</td>\n",
       "      <td>-1.00</td>\n",
       "      <td>-1.00</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 94 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   id  label  college    rank  total_people  rank_percent  price_count  \\\n",
       "0   0      0      9.0     1.0        2933.0      0.000341        602.0   \n",
       "1   1      0      9.0     2.0        2933.0      0.000682        666.0   \n",
       "2   8      0      6.0  1565.0        1570.0      0.996815       1285.0   \n",
       "3   9      0      6.0  1570.0        1570.0      1.000000       1569.0   \n",
       "4  10      0      3.0     1.0        2304.0      0.000434        827.0   \n",
       "\n",
       "   price_sum  price_avg  price_max       ...         other_avg  other_max  \\\n",
       "0    4784.14   7.830016      200.0       ...             -1.00      -1.00   \n",
       "1    5876.97   8.784709      300.0       ...             -1.00      -1.00   \n",
       "2   10779.15   8.388444      200.0       ...             -1.00      -1.00   \n",
       "3   14174.15   9.033875      200.0       ...             61.13      61.13   \n",
       "4    5976.01   7.191348      200.0       ...             -1.00      -1.00   \n",
       "\n",
       "   other_min  other_median  hospital_count  hospital_sum  hospital_avg  \\\n",
       "0      -1.00         -1.00            -1.0          -1.0          -1.0   \n",
       "1      -1.00         -1.00            -1.0          -1.0          -1.0   \n",
       "2      -1.00         -1.00            -1.0          -1.0          -1.0   \n",
       "3      61.13         61.13            -1.0          -1.0          -1.0   \n",
       "4      -1.00         -1.00            -1.0          -1.0          -1.0   \n",
       "\n",
       "   hospital_max  hospital_min  hospital_median  \n",
       "0          -1.0          -1.0             -1.0  \n",
       "1          -1.0          -1.0             -1.0  \n",
       "2          -1.0          -1.0             -1.0  \n",
       "3          -1.0          -1.0             -1.0  \n",
       "4          -1.0          -1.0             -1.0  \n",
       "\n",
       "[5 rows x 94 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_test.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "X = train_test.ix[:, train_test.columns != 'label']\n",
    "y = train_test.ix[:, train_test.columns == 'label']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "X_train, X_test, y_train, y_test = train_test_split(X,y,test_size = 0.3, random_state = 42)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/kuhung/anaconda2/lib/python2.7/site-packages/ipykernel/__main__.py:2: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  from ipykernel import kernelapp as app\n"
     ]
    }
   ],
   "source": [
    "train=X_train\n",
    "train['label']=y_train\n",
    "\n",
    "test=X_test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "target = 'label'\n",
    "IDcol = 'id'\n",
    "ids = test['id'].values\n",
    "predictors = [x for x in train.columns if x not in [target]]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Oversample\n",
    "Oversampling1000 = train.loc[train.label == 1000]\n",
    "Oversampling1500 = train.loc[train.label == 1500]\n",
    "Oversampling2000 = train.loc[train.label == 2000]\n",
    "for i in range(5):\n",
    "    train = train.append(Oversampling1000)\n",
    "for j in range(8):\n",
    "    train = train.append(Oversampling1500)\n",
    "for k in range(10):\n",
    "    train = train.append(Oversampling2000)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>college</th>\n",
       "      <th>rank</th>\n",
       "      <th>total_people</th>\n",
       "      <th>rank_percent</th>\n",
       "      <th>price_count</th>\n",
       "      <th>price_sum</th>\n",
       "      <th>price_avg</th>\n",
       "      <th>price_max</th>\n",
       "      <th>price_min</th>\n",
       "      <th>...</th>\n",
       "      <th>other_max</th>\n",
       "      <th>other_min</th>\n",
       "      <th>other_median</th>\n",
       "      <th>hospital_count</th>\n",
       "      <th>hospital_sum</th>\n",
       "      <th>hospital_avg</th>\n",
       "      <th>hospital_max</th>\n",
       "      <th>hospital_min</th>\n",
       "      <th>hospital_median</th>\n",
       "      <th>label</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>613</th>\n",
       "      <td>1874</td>\n",
       "      <td>9.0</td>\n",
       "      <td>1423.0</td>\n",
       "      <td>2933.0</td>\n",
       "      <td>0.485169</td>\n",
       "      <td>1245.0</td>\n",
       "      <td>8227.78</td>\n",
       "      <td>6.603355</td>\n",
       "      <td>100.0</td>\n",
       "      <td>-15.00</td>\n",
       "      <td>...</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>1500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4030</th>\n",
       "      <td>12364</td>\n",
       "      <td>8.0</td>\n",
       "      <td>1280.0</td>\n",
       "      <td>2830.0</td>\n",
       "      <td>0.452297</td>\n",
       "      <td>2106.0</td>\n",
       "      <td>13355.65</td>\n",
       "      <td>6.329692</td>\n",
       "      <td>1100.0</td>\n",
       "      <td>-13.20</td>\n",
       "      <td>...</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3582</th>\n",
       "      <td>10940</td>\n",
       "      <td>13.0</td>\n",
       "      <td>725.0</td>\n",
       "      <td>2714.0</td>\n",
       "      <td>0.267133</td>\n",
       "      <td>1729.0</td>\n",
       "      <td>10806.25</td>\n",
       "      <td>6.250000</td>\n",
       "      <td>200.0</td>\n",
       "      <td>-10.00</td>\n",
       "      <td>...</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6237</th>\n",
       "      <td>18765</td>\n",
       "      <td>19.0</td>\n",
       "      <td>794.0</td>\n",
       "      <td>2305.0</td>\n",
       "      <td>0.344469</td>\n",
       "      <td>1308.0</td>\n",
       "      <td>10497.23</td>\n",
       "      <td>8.007040</td>\n",
       "      <td>300.0</td>\n",
       "      <td>-0.96</td>\n",
       "      <td>...</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1430</th>\n",
       "      <td>4457</td>\n",
       "      <td>6.0</td>\n",
       "      <td>1474.0</td>\n",
       "      <td>1570.0</td>\n",
       "      <td>0.938854</td>\n",
       "      <td>1957.0</td>\n",
       "      <td>12735.75</td>\n",
       "      <td>6.507793</td>\n",
       "      <td>200.0</td>\n",
       "      <td>-3.54</td>\n",
       "      <td>...</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 94 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         id  college    rank  total_people  rank_percent  price_count  \\\n",
       "613    1874      9.0  1423.0        2933.0      0.485169       1245.0   \n",
       "4030  12364      8.0  1280.0        2830.0      0.452297       2106.0   \n",
       "3582  10940     13.0   725.0        2714.0      0.267133       1729.0   \n",
       "6237  18765     19.0   794.0        2305.0      0.344469       1308.0   \n",
       "1430   4457      6.0  1474.0        1570.0      0.938854       1957.0   \n",
       "\n",
       "      price_sum  price_avg  price_max  price_min  ...    other_max  other_min  \\\n",
       "613     8227.78   6.603355      100.0     -15.00  ...         -1.0       -1.0   \n",
       "4030   13355.65   6.329692     1100.0     -13.20  ...         -1.0       -1.0   \n",
       "3582   10806.25   6.250000      200.0     -10.00  ...         -1.0       -1.0   \n",
       "6237   10497.23   8.007040      300.0      -0.96  ...         -1.0       -1.0   \n",
       "1430   12735.75   6.507793      200.0      -3.54  ...         -1.0       -1.0   \n",
       "\n",
       "      other_median  hospital_count  hospital_sum  hospital_avg  hospital_max  \\\n",
       "613           -1.0            -1.0          -1.0          -1.0          -1.0   \n",
       "4030          -1.0            -1.0          -1.0          -1.0          -1.0   \n",
       "3582          -1.0            -1.0          -1.0          -1.0          -1.0   \n",
       "6237          -1.0            -1.0          -1.0          -1.0          -1.0   \n",
       "1430          -1.0            -1.0          -1.0          -1.0          -1.0   \n",
       "\n",
       "      hospital_min  hospital_median  label  \n",
       "613           -1.0             -1.0   1500  \n",
       "4030          -1.0             -1.0      0  \n",
       "3582          -1.0             -1.0      0  \n",
       "6237          -1.0             -1.0      0  \n",
       "1430          -1.0             -1.0      0  \n",
       "\n",
       "[5 rows x 94 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "## Evaluation \n",
    "def f1_macro(label_truth, predictions):\n",
    "    df=pd.DataFrame(columns=[\"subsidy_x\",\"subsidy_y\"])\n",
    "    df.subsidy_y=predictions\n",
    "    df.subsidy_x=np.array(label_truth)\n",
    "    df.subsidy_y = df.subsidy_y.apply(lambda x:int(x))\n",
    "\n",
    "    \n",
    "    correct = df[df['subsidy_x'] == df['subsidy_y']]\n",
    "    s = 0\n",
    "    for i in [1000, 1500, 2000]:\n",
    "        r = float(sum(correct['subsidy_y'] == i))/sum(df['subsidy_x'] == i)\n",
    "        p = float(sum(correct['subsidy_y'] == i))/sum(df['subsidy_y'] == i)\n",
    "        f = r*p*2/(r+p)\n",
    "        if not np.isnan(f):\n",
    "            s += (float(sum(df['subsidy_x'] == i))/df.shape[0])*f\n",
    "    return s  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn import ensemble"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"\\n## ensemble\\nclf1 = XGBClassifier(max_depth=5,objective='multi:softmax',n_estimators=100,seed=0)\\nclf2 = GradientBoostingClassifier(n_estimators=200,random_state=2016)\\nclf3 = GradientBoostingClassifier(n_estimators=200,random_state=42)\\n\\nclfs=ensemble.VotingClassifier(estimators=[('xgb',clf1),('GBM',clf2),('RF',clf3)],voting='hard')\\n\\nclfs = clfs.fit(train[predictors],train[target])\\nresult = clfs.predict(test[predictors])\\n\\nf1_macro(y_test,result)\\n\""
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "## ensemble\n",
    "clf1 = XGBClassifier(max_depth=5,objective='multi:softmax',n_estimators=100,seed=0)\n",
    "clf2 = GradientBoostingClassifier(n_estimators=200,random_state=2016)\n",
    "clf3 = GradientBoostingClassifier(n_estimators=200,random_state=42)\n",
    "\n",
    "clfs=ensemble.VotingClassifier(estimators=[('xgb',clf1),('GBM',clf2),('RF',clf3)],voting='hard')\n",
    "\n",
    "clfs = clfs.fit(train[predictors],train[target])\n",
    "result = clfs.predict(test[predictors])\n",
    "\n",
    "f1_macro(y_test,result)\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.02792262079090802"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# model\n",
    "clf=XGBClassifier(max_depth=4,objective='multi:softmax',n_estimators=100,seed=0)\n",
    "#clf = GradientBoostingClassifier(n_estimators=200,random_state=2016)\n",
    "#clf = RandomForestClassifier(n_estimators=150,random_state=42,max_depth=10)\n",
    "clf = clf.fit(train[predictors],train[target])\n",
    "result = clf.predict(test[predictors])\n",
    "f1_macro(y_test,result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\n## Evaluation\\ndef score(df):\\n    # df\\xe6\\x9c\\x89\\xe4\\xb8\\x89\\xe5\\x88\\x97\\xef\\xbc\\x8cID:\\xe5\\xad\\xa6\\xe7\\x94\\x9fID,subsidy_x:\\xe5\\xae\\x9e\\xe9\\x99\\x85\\xe5\\xa5\\x96\\xe5\\xad\\xa6\\xe9\\x87\\x91\\xe9\\x87\\x91\\xe9\\xa2\\x9d,subsidy_y:\\xe9\\xa2\\x84\\xe6\\xb5\\x8b\\xe5\\xa5\\x96\\xe5\\xad\\xa6\\xe9\\x87\\x91\\xe9\\x87\\x91\\xe9\\xa2\\x9d\\n    correct = test_result[test_result[\\'subsidy_x\\'] == test_result[\\'subsidy_y\\']]\\n    s = 0\\n    for i in [1000, 1500, 2000]:\\n        r = float(sum(correct[\\'subsidy_y\\'] == i))/sum(test_result[\\'subsidy_x\\'] == i)\\n        p = float(sum(correct[\\'subsidy_y\\'] == i))/sum(test_result[\\'subsidy_y\\'] == i)\\n        f = r*p*2/(r+p)\\n        if not np.isnan(f):\\n            s += (float(sum(test_result[\\'subsidy_x\\'] == i))/test_result.shape[0])*f\\n    print(s)\\n\\ntest_result = pd.DataFrame(columns=[\"studentid\",\"subsidy_x\",\"subsidy_y\"])\\ntest_result.studentid = ids\\n\\ntest_result.subsidy_x =np.array(y_test)\\ntest_result.subsidy_y = result\\ntest_result.subsidy_y = test_result.subsidy_y.apply(lambda x:int(x))\\n\\nscore(test_result)\\n\\n'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "## Evaluation\n",
    "def score(df):\n",
    "    # df有三列，ID:学生ID,subsidy_x:实际奖学金金额,subsidy_y:预测奖学金金额\n",
    "    correct = test_result[test_result['subsidy_x'] == test_result['subsidy_y']]\n",
    "    s = 0\n",
    "    for i in [1000, 1500, 2000]:\n",
    "        r = float(sum(correct['subsidy_y'] == i))/sum(test_result['subsidy_x'] == i)\n",
    "        p = float(sum(correct['subsidy_y'] == i))/sum(test_result['subsidy_y'] == i)\n",
    "        f = r*p*2/(r+p)\n",
    "        if not np.isnan(f):\n",
    "            s += (float(sum(test_result['subsidy_x'] == i))/test_result.shape[0])*f\n",
    "    print(s)\n",
    "\n",
    "test_result = pd.DataFrame(columns=[\"studentid\",\"subsidy_x\",\"subsidy_y\"])\n",
    "test_result.studentid = ids\n",
    "\n",
    "test_result.subsidy_x =np.array(y_test)\n",
    "test_result.subsidy_y = result\n",
    "test_result.subsidy_y = test_result.subsidy_y.apply(lambda x:int(x))\n",
    "\n",
    "score(test_result)\n",
    "\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"\\n## Feature importance\\n%matplotlib \\nclf=XGBClassifier(max_depth=5,objective='multi:softmax',n_estimators=100,seed=0)\\nfeat_imp=pd.Series(clf.booster().get_fscore()).sort_values(ascending=False)\\nfeat_imp.plot(kind='bar', title='Feature Importances')\\n\\n\""
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "## Feature importance\n",
    "%matplotlib \n",
    "clf=XGBClassifier(max_depth=5,objective='multi:softmax',n_estimators=100,seed=0)\n",
    "feat_imp=pd.Series(clf.booster().get_fscore()).sort_values(ascending=False)\n",
    "feat_imp.plot(kind='bar', title='Feature Importances')\n",
    "\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [Root]",
   "language": "python",
   "name": "Python [Root]"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
